// pages/Member/member_SelfHelpIntegral/member_SelfHelpIntegral_Record/member_SelfHelpIntegral_Record.js

//获取应用实例(获取app.js全局变量必须获取应用实例)
const App = getApp()

//网络请求封装
import Request_post from "../../../../../request/Request_post"
import Request_get from "../../../../../request/Request_get"

//系统设置项目:(请求地址-在封装中已经引入，这里不需要;   api调用的Appid-partner_app_id;   渠道ID-as_appid)
import config from '../../../../../config/config'; 

//引入时间函数
var dateArray = require("../../../../../utils/CustomFunction/getDayFirstNowLast.js")
var time = require("../../../../../utils/CustomFunction/getNowTime.js")

//引入日期时间：（格式化、反格式化）函数
var formatDate = require("../../../../../utils/CustomFunction/dateFormat.js")
var unformatDate = require("../../../../../utils/CustomFunction/dateUnFormat.js")



Page({

  /**
   * 页面的初始数据
   */
  data: {

    //Title图片的网络地址链接
    Title_Image:config.imageUrl+"title_member_SelfHelpIntegral_Record.jpg",
    //待处理-角标
    WaitProcessing:config.imageUrl+"WaitProcessing.png",
    //已补登-角标
    AlreadyAddItg:config.imageUrl+"AlreadyAddItg.png",
    //已驳回-角标
    AlreadyRejected:config.imageUrl+"AlreadyRejected.png",

    calendar:config.imageUrl+"calendar.png",

    itg_camera_logo:config.imageUrl+"itg_camera_logo.png",
    itg_scancode_logo:config.imageUrl+"itg_scancode_logo.png",
    
    //空页面
		EmptyPage:config.imageUrl+"EmptyPage.png",

    index:0,

    Tabs_list:[
      {name:"全部",isActive:true},
			{name:"已补登",isActive:false},
			{name:"待处理",isActive:false},
			{name:"被驳回",isActive:false}
		],

  },

  bindImgError:function(e){
    this.setData({
      Title_Image: "../../../../../image/title_member_SelfHelpIntegral_Record.jpg"
    })
  },

  

  //接收标签页自定义组件，点击事件---子组件传递过来的参数
	handleItemChang(e){

		const index = e.detail.index;
		const Tabs_list = this.data.Tabs_list;
		//方式一：使用forEach 遍历数组，遍历数组的时候，修改了v，也会导致源数组被修改
		Tabs_list.forEach((v,i)=>i===index? v.isActive=true:v.isActive=false);
		this.setData({
			Tabs_list:Tabs_list,
			index:index
    })
    if(index == 0){
      var that = this
      /** Api请求：12-002 会员积分补登申请列表查询  **/
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "all",   //全部
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }else if(index == 1){
      var that = this
      /** Api请求：12-002 会员积分补登申请列表查询  **/
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "03",   //已补登
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }else if(index == 2){
      var that = this
      /** Api请求：12-002 会员积分补登申请列表查询  **/
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "01",   //待处理
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }else if(index == 3){
      var that = this
      /** Api请求：12-002 会员积分补登申请列表查询  **/
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "02",   //驳回申请
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }
		},



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    //获取本月第一天 & 最后一天日期
    const getdateArray = dateArray.getDayFirstNowLast()
    this.setData({
      bdate:getdateArray[0],
      edate:getdateArray[2]
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**点击开始日期 */
  bindbdateChange: function(e) {
    var that = this
		that.setData({
      bdate:unformatDate.DatString(e.detail.value)
    })
    //修改开始时间后，4种状态的数据按修改后的时间（开始时间）重新获取
    if(that.data.index == 0){
      var that = this
      Request_get.get(
      config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
      {
        rqtmodid: "all",
        stsid: "all",   //全部
        bdtm: that.data.bdate+"000000",
        edtm: that.data.edate+"235959"
      },
      function(res){
        if(res){
          that.setData({makeup_list:res.return_data})
        }
      })
    }else if(that.data.index == 1){
      var that = this
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "03",   //已补登
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }else if(that.data.index == 2){
      var that = this
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "01",   //待处理
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }else if(that.data.index == 3){
      var that = this
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "02",   //驳回申请
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }
    


   },

  /**点击截至日期 */
  bindedateChange: function(e) {
    var that = this
    that.setData({
      edate:unformatDate.DatString(e.detail.value)
    })
    //修改截至时间后，4种状态的数据按修改后的时间（截至时间）重新获取
    if(that.data.index == 0){
      var that = this
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "all",   //全部
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })

    }else if(that.data.index == 1){
      var that = this
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "03",   //已补登
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }else if(that.data.index == 2){
      var that = this
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "01",   //待处理
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }else if(that.data.index == 3){
      var that = this
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: "02",   //驳回申请
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        })
    }



  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
    //页面打开，首先请求一次积分补登记录列表api
    var that = this
    // 选择标签页的index重置为 当前标签所对应的状态--stsid  /**{{如果选择标签页有变化，这里需要手动对应调整}} */
    if(that.data.index == 0){
      that.setData({ stsid:"all"})
    }else if(that.data.index == 1){
      that.setData({ stsid:"03"})
    }else if(that.data.index == 2){
      that.setData({ stsid:"01"})
    }else if(that.data.index == 3){
      that.setData({ stsid:"02"})
    }

    getApp().loginPromise.then(v => {	//app.js的Promise成功回调（全局变量赋值成功后才执行请求）
      Request_get.get(
        config.domainName+'api_wxmkt_server/mbritgextadd/listmbritgextadd',
        {
          rqtmodid: "all",
          stsid: that.data.stsid, 
          bdtm: that.data.bdate+"000000",
          edtm: that.data.edate+"235959"
        },
        function(res){
          if(res){
            that.setData({makeup_list:res.return_data})
          }
        }
      )
    })

    
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})